<template>
	<ayjDialog ref="dialoRef" :title="'设置分润结算'" width="30%" @closeFun="close" :slotFooter="true" height="700">
		<div class="content">
			<h3>结算设置</h3>
			<div class="set-profit-box">
				<div class="flex_between">
					<div>佣金结算设置</div>
					<div>
						<el-switch v-model="objectForm.is_st2Value"></el-switch>
					</div>
				</div>
				<div class="lins mt10"></div>
				<div class="flex_row mt10">
					<span>分销规则达到后</span>
					<div class="input-box">
						<input class="inpt" v-model="objectForm.day_st2" min="0" type="number"></input>
					</div>
					<span>天才能结算</span>
				</div>
			</div>
			<h3>提现设置</h3>
			<div class="set-profit-box">
				<div class="flex_between">
					<div>佣金提现设置</div>
					<div>
						<el-switch v-model="objectForm.is_st3Value"></el-switch>
					</div>
				</div>
				<div class="lins mt10"></div>
				<div class="flex_row mt10">
					<span>控制订单结算后</span>
					<div class="input-box">
						<input class="inpt" v-model="objectForm.day_st3" min="0" type="number"></input>
					</div>
					<span>天才能提现</span>
				</div>
			</div>
			<div style="height:50px;"></div>
		</div>
		<template #footer>
			<div class="flex_between">
				<div></div>
				<div>
					<el-button @click="close" size="mini">取消</el-button>
					<el-button type="primary" @click="editQtySure" size="mini">确定</el-button>
				</div>
			</div>
		</template>
	</ayjDialog>
</template>

<script setup>
import { ref, onMounted, defineProps, defineEmits, getCurrentInstance, watch, computed, defineExpose } from '@vue/composition-api'
import config from "@/js/conf/Config.js"
import { priceInput } from '@/utils/common.js'

// 获取当前组件实例
const { proxy } = getCurrentInstance()
const sLoading = ref(false)

const objectForm = ref({
	shopid_yd: '',
	is_st2: '',
	day_st2: '',
	is_st3: '',
	day_st3: '',
	is_st2Value: true,
	is_st3Value: true,
})

const editQtySure = async () => {
	console.log("objectForm.value=", objectForm.value)
	const params = {
		...objectForm.value,
		is_st2: objectForm.value.is_st2Value ? 1 : 2,
		is_st3: objectForm.value.is_st3Value ? 1 : 2,
	}
	const res = await proxy.$api({ url: config.yx_ds_rule_save, data: params })
	if (res.status == 1) {
		proxy.$message.success(res?.msg || '操作成功')
		setTimeout(() => {
			close()
		}, 1000)
	} else {
		proxy.$message.error(res?.msg || '操作失败')
	}
}

const getRuleInfo = async () => {
	const res = await proxy.$api({ url: config.yx_ds_rule_info, data: {} })
	if (res.status == 1) {
		objectForm.value = {
			...res.data.rule_info,
			is_st2Value: res.data.rule_info.is_st2 == '1',
			is_st3Value: res.data.rule_info.is_st3 == '1',
		}
	}
}

const dialoRef = ref(null)
const open = () => {
	getRuleInfo()
	dialoRef.value.open()
}

const close = () => {
	dialoRef.value.close()
}

onMounted(() => { })

defineExpose({
	open,
	close
})

</script>

<style lang="scss" scoped>
.set-profit {
	.set-profit-box {
		font-size: 14px;
		background-color: #f9f9f9;
		padding: 14px 20px;
		border-radius: 8px;
		margin-bottom: 10px;
	}
}

.lins {
	height: 1px;
	width: 100%;
	background-color: #e5e5e5;
}

.input-box {
	margin: 0 10px;
}

.inpt {
	font-size: 30px;
	font-weight: 500;
	width: 80px;
	text-align: center;
	border-bottom: 1px solid #ec6262;
	padding: 0 10px;
	color: #ec6262;
}
</style>